<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl-NL" lang="nl-NL">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta name="Author" content="Hampei">
 <title>Client</title>
 <meta Name="description" Content="description here">
 <meta Name="keywords" Content="keywords for search engines">
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript">
	//<![CDATA[
	var toolApplet = null;
	/** 
	* Initialize annotationFileEditor. 
	* Will be called by the toolApplet when that has finished loading. 
	* @param applet Reference to the toolApplet. 
	*/
	//var guiframe;
	function appletLoaded( tapplet ) {
		//alert ('applet loaded');
		toolApplet = tapplet;
	}

	function getMessageListoud() {
		frames['guiframe'].location.href = "messages.html";
	}

	function showIncommingMessage() {
		toolApplet.transformEBSchema( 'tf-read.xml' );
			
		// This should become a bit more dynamic maybe. The output location is
		// specified in tf-read.xml (see also messages.xhtml).
		frames['guiframe'].location.href = 
		'../../prototype-gs1/output/message.xhtml';
	}
	
	function test (fileName) {
		new Ajax.Request('http://localhost:8088/get_message?file='+fileName, {
		  method: 'get',
		  onSuccess: function(transport) {
		    alert("getFile" +transport.responseText);
		  },
		  onFailure: function() {
			  alert("get file failed");
		  }
		});
	}
	function fetch_file(remoteFileName, localFileName) {
		new Ajax.Request('http://localhost:8088/get_message?file='+fileName, {
		  method: 'get',
		  onSuccess: function(transport) {
		    alert("getFile" +transport.responseText);
		  },
		  onFailure: function() {
			  alert("get file failed");
		  }
		});
	}
	function getMessageList() {
		new Ajax.Request('http://localhost:8088/get_message_list', {
		  method: 'get',
		  onSuccess: function(transport) {
		    showMessageList(transport.responseText);
		  },
		  onFailure: function() {
			  alert("get file failed");
		  }
		});	
	}	
	function showMessageList(filelist) {
		xmllist = getXMLParser().parseFromString(filelist,'text/xml');
		var filearray = xmllist.getElementsByTagName('file');
		var res = '<ul>';
		for(var i=0,file; file=filearray[i++];) {
			 res += '<li><a href="#" onclick="getMessage(\''+
			  file.getAttribute('src')+'\', \'' +
			  file.getAttribute('schema') + '\')">'+
			  file.getAttribute('src')+'</a></li>';
		}
		res += '</ul>';
		print_txt(res);
	}
	function getMessage(fileName, xsd) {
		new Ajax.Request('http://localhost:8088/get_message?file=' + fileName, {
		  method: 'get',
		  onSuccess: function(transport) {
		    showMessage(transport.responseText, xsd);
		  },
		  onFailure: function() {
			  alert("get file failed");
		  }
		});				
	}
	function showMessage(xml, xsd) {
		alert(xml + xsd);		
	}
	function print_txt(txt) {
		document.frames['guiframe'].document.open();
		document.frames['guiframe'].document.write(txt);
		document.frames['guiframe'].document.close();
	}
	/*
	* Return an object which can parse an xml-string to an xml-tree using the 
	* interface of the W3C DOMParser.
	* doc = getXMLParser().parseFromString(txt,'text/xml');
	*/
	function getXMLParser() {
		if (typeof DOMParser != 'undefined') {
			return new DOMParser();
		} else if (window.ActiveXObject) {
			var parser = new Object();
			parser.parseFromString = function (xmlstr, format) {
				var doc = new ActiveXObject('Microsoft.XMLDOM');
				doc.async = 'false';
				doc.loadXML(xmlstr);
				return doc;	
			};
			return parser;
		} else {
			alert('No DOM-parser in browser');
		}
	};
	
	
	
	function newOrder( ) {
		var order_config;
		if (!!(window.attachEvent && !window.opera)) { //ie
			order_config = 'transform-config-ie.xml'
			resultPath = "../../prototype-gs1/output" + 
			 "/FoodservicePurchaseOrder.html";
		} else { //ff
			order_config = 'transform-config.xml'
			resultPath = "../../prototype-gs1/output" + 
			 "/FoodservicePurchaseOrder.xhtml";
		}
	
		toolApplet.transformEBSchema( order_config );
		
		// TODO: Write some function in the applet which gives the path of the result
		// document of the transformation.
		//resultPath = toolApplet.getResultPath( transformConfig );
	
	
		//alert( resultPath ).location.href;
		frames['guiframe'].location.href = resultPath;
	
	}
	
	//]]>
</script>

</head>
<body>

<div>
 <applet id="toolapplet" code="com.flowcanto.client.ToolApplet" 
 	codebase=".." 
 	archive="java/lib/toolapplet.jar, ../lib/saxon8.jar, java/lib/plugin.jar" 
 	mayscript="true" width="0" height="0">
   <param name="cache_option" value="No">
 </applet>
</div>

<div>
	<a href="#" onclick="newOrder()">create new order</a>
	<a href="#" onclick="getMessageList()">Inbox</a>
  <a href="#" onclick="getFile('invoice_20031234-1.xml')">test get file</a>
  <a href="#" onclick="test_get()">test get and print</a>
</div>

<iframe id="guiframe" name="guiframe" src="" style="width: 100%; height: 600px" >
</iframe>
 
</body>
</html>